package com.augmentum.oes.controller;

import org.apache.log4j.Logger;
import org.springframework.dao.DataAccessException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.servlet.ModelAndView;

import com.augmentum.oes.Constants;
import com.augmentum.oes.exception.ParameterException;
import com.augmentum.oes.exception.ServiceException;

public class ExceptionHandle {

    private Logger log = Logger.getLogger(ExceptionHandle.class);

    @ExceptionHandler(ServiceException.class)
    public ModelAndView dealPass(ServiceException e) {
        ModelAndView mav = new ModelAndView();
        mav.setViewName(Constants.LOGIN_PAGE);
        mav.addObject(Constants.TIP_MESSAGE, "User is not exist!");
        return mav;
    }

    @ExceptionHandler(DataAccessException.class)
    public String dealData(DataAccessException e) {
        log.error(e.getMessage(), e);
        return Constants.ERROR_PAGE;
    }

    @ExceptionHandler(ParameterException.class)
    public ModelAndView dealParam(ParameterException e) {
        ModelAndView mav = new ModelAndView();
        mav.addObject(Constants.TIP_MESSAGE, "User is not exist!");
        mav.setViewName(Constants.LOGIN_PAGE);
        return mav;
    }
}
